<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="/css/common.css" rel="stylesheet" type="text/css" />
<style>
.wrapContent {height:600px;margin:0 auto;padding:0 30px;}
.center {text-align:center;}
.block {padding:10px 30px;}
.lineHeight{height:34px;line-height:34px;}
.right{text-align:right;width:120px;vertical-align:top}
.left {float:left;}
.topBorder {border-top:1px solid #000;}
.rightBorder {border-right:1px solid #000;}
</style>
</head>
<body>
<div class="wrapContent">
	<div class="block">
		<h2 class="center">库存查询</h2>
		<div class="block">
			<span>请输入硒鼓类型：</span>
			<input id="type" style="width:200px;" />
			<input id="submit" type="button" class="submitBtn" value="查询"/>
			<?php if ($userInfo['level'] > 1000){ ?>
			<span style="margin-left:10px"><a href="/admin/inventory.php?op=add">添加库存</a></span>
			<span style="margin-left:10px"><a id="modify">修改库存</a></span>
			<?php } ?>
		</div>
		<div id="queryResult" class="block center" style="display:none;">
			<table id="queryResultTable" cellpadding="0" cellspacing="0" style="width:80%;border:1px solid #000;">
				<!-- 
				<thead class="lineHeight">
					<td width="50%" class="rightBorder center">库房</td>
					<td width="50%" class="center">个数</td>
				</thead>
				<tr class="lineHeight">
					<td class="topBorder rightBorder center">北京</td>
					<td class="topBorder center">20</td>
				</tr>
				 -->
			</table>
		</div>
		<div id="queryNoResult" class="block center" style="margin:30px 0 0 0;display:none;">没有找到匹配的类型，请联系管理员添加库存！ </div>
	</div>
</div>
</body>
<script src="/js/lib.min.js" type="text/javascript"></script>
<script type="text/javascript">
<?php echo "var warehouses = " . json_encode($warehouse). ";\n" ?>
var typeInput = $('#type'),
	submitBtn = $('#submit');
submitBtn.attr({onclick:function(){
	var type = $.trim(typeInput.val());
	if (!type){
		alert('请输入查询型号');
		return ;
	}
	
	submitBtn.val('正在处理，请稍后...');
	submitBtn[0].disabled = true;
	
	$.ajax({
		url:'/admin/inventory.php?op=doQuery',
		data:{'type':type},
		type:'POST',
		callback:function(res){
		submitBtn.val('查询');
		submitBtn[0].disabled = false;
			if (res.errno == '0'){
				var result = $('#queryResult'),
					table = $('#queryResultTable'),
					noResult = $('#queryNoResult');
				if (res.data) {
					/*
					table.html('');
					var trHtml = '<td width="50%" class="rightBorder center">库房</td><td width="50%" class="center">个数</td>';
						$.createEle('tr', {'className':'lineHeight'}).html(trHtml).appendTo(table);
					$.each(res.data, function(count, id){
						trHtml = '<td width="50%" class="topBorder rightBorder center">'+warehouses[id]+'</td><td class="topBorder center">'+count+'</td>';
						$.createEle('tr', {'className':'lineHeight'}).html(trHtml).appendTo(table);						
					});
					*/
					var htmlStr = '<tr class="lineHeight"><td width="50%" class="rightBorder center">库房</td><td width="50%" class="center">个数</td></tr>';
					$.each(res.data, function(count, id) {
						htmlStr += '<tr class="lineHeight"><td width="50%" class="topBorder rightBorder center">'+warehouses[id]+'</td><td class="topBorder center">'+count+'</td></tr>';
					});
					table.html(htmlStr);
					result.show();
					noResult.hide();
					$('#modify').attr({href:'/admin/inventory.php?op=modify&type_id='+res.type});
				}else{
					result.hide();
					noResult.show();
				}
			}else{
				alert(res.errmsg);
			}
		}
	})
}});	
</script>
</html>